#!/usr/bin/env python3
# -*-coding:utf-8-*-
# author:link
import sys
import os
sys.path.append(os.getcwd())
import logging
import os.path
import time

class Logger():
    def __init__(self,logger):
        self.logger=logging.getLogger(logger)
        self.logger.handlers.clear()
        self.logger.setLevel(logging.DEBUG)
        rq=time.strftime('%Y%m%d%H%M',time.localtime(time.time()))
        root_path = os.path.split(os.path.realpath(__file__))[0]
        log_path= root_path + '/logs/'
        print(log_path)
        log_name=log_path + rq + '.log'
        fh=logging.FileHandler(log_name)
        fh.setLevel(logging.INFO)
        ch = logging.StreamHandler()
        ch.setLevel(logging.INFO)
        formater=logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        fh.setFormatter(formater)
        ch.setFormatter(formater)
        self.logger.addHandler(fh)
        self.logger.addHandler(ch)
    def getlog(self):
        return self.logger
